// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   change_ok.java

package ecommerce.crm;

import include.get_sql.getInsertSql;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class change_ok extends HttpServlet
{

	public change_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 crm_db = new nseer_db_backup1(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		ValidataTag vt = new ValidataTag();
		counter count = new counter(dbApplication);
		getInsertSql getInsertSql = new getInsertSql();
		try
		{
			if (crm_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String fileKind_chain = request.getParameter("fileKind_chain");
				String chain_id = Divide1.getId(fileKind_chain);
				String chain_name = Divide1.getName(fileKind_chain);
				String responsible_person_ID = "";
				String responsible_person_name = "";
				String customer_ID = request.getParameter("customer_ID");
				String sql2 = (new StringBuilder("select * from crm_config_file_kind where file_id='")).append(chain_id).append("'").toString();
				String customer_name = request.getParameter("customer_name");
				String customer_address = request.getParameter("customer_address");
				String type = request.getParameter("type");
				String customer_class = request.getParameter("class");
				String gather_sum_limit = request.getParameter("gather_sum_limit");
				String gather_period_limit = request.getParameter("gather_period_limit");
				String contact_period_limit = request.getParameter("contact_period_limit");
				String used_customer_name = request.getParameter("used_customer_name");
				String customer_bank = request.getParameter("customer_bank");
				String customer_account = request.getParameter("customer_account");
				String customer_web = request.getParameter("customer_web");
				String customer_tel1 = request.getParameter("customer_tel1");
				String customer_tel2 = request.getParameter("customer_tel2");
				String customer_fax = request.getParameter("customer_fax");
				String customer_postcode = request.getParameter("customer_postcode");
				String contact_person1 = request.getParameter("contact_person1");
				String contact_person1_department = request.getParameter("contact_person1_department");
				String contact_person1_duty = request.getParameter("contact_person1_duty");
				String contact_person1_sex = request.getParameter("contact_person1_sex");
				String contact_person1_office_tel = request.getParameter("contact_person1_office_tel");
				String contact_person1_home_tel = request.getParameter("contact_person1_home_tel");
				String contact_person1_mobile = request.getParameter("contact_person1_mobile");
				String contact_person1_email = request.getParameter("contact_person1_email");
				String contact_person2 = request.getParameter("contact_person2");
				String contact_person2_department = request.getParameter("contact_person2_department");
				String contact_person2_duty = request.getParameter("contact_person2_duty");
				String contact_person2_sex = request.getParameter("contact_person2_sex");
				String contact_person2_office_tel = request.getParameter("contact_person2_office_tel");
				String contact_person2_home_tel = request.getParameter("contact_person2_home_tel");
				String contact_person2_mobile = request.getParameter("contact_person2_mobile");
				String contact_person2_email = request.getParameter("contact_person2_email");
				String changer_ID = request.getParameter("changer_ID");
				String changer = request.getParameter("changer");
				String change_time = request.getParameter("change_time");
				String lately_change_time = request.getParameter("lately_change_time");
				String file_change_amount = request.getParameter("file_change_amount");
				int change_amount = Integer.parseInt(file_change_amount) + 1;
				String bodyc = new String(request.getParameter("invoice_info").getBytes("UTF-8"), "UTF-8");
				String invoice_info = exchange.toHtml(bodyc);
				String bodya = new String(request.getParameter("demand").getBytes("UTF-8"), "UTF-8");
				String demand = exchange.toHtml(bodya);
				String bodyb = new String(request.getParameter("remark").getBytes("UTF-8"), "UTF-8");
				String remark = exchange.toHtml(bodyb);
				String checker_ID = request.getParameter("checker_ID");
				int n = 0;
				if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "crm_file", "customer_ID", customer_ID, "check_tag").equals("1"))
				{
					if (n == 0)
					{
						ResultSet rs2 = crm_db.executeQuery(sql2);
						if (rs2.next())
						{
							try
							{
								String sqloo = (new StringBuilder("select * from crm_file where customer_ID='")).append(customer_ID).append("'").toString();
								ResultSet rs8 = crm_db.executeQuery(sqloo);
								if (rs8.next())
								{
									String sqll = (new StringBuilder("insert into crm_file_dig(CHAIN_ID,CHAIN_NAME,CUSTOMER_ID,CUSTOMER_NAME,CUSTOMER_NICK,CUSTOMER_ADDRESS,CUSTOMER_CLASS,TYPE,CUSTOMER_BANK,CUSTOMER_ACCOUNT,CUSTOMER_WEB,CUSTOMER_TEL1,CUSTOMER_TEL2,CUSTOMER_EMAIL,CUSTOMER_FAX,CUSTOMER_POSTCODE,CONTACT_PERSON1,CONTACT_PERSON1_DEPARTMENT,CONTACT_PERSON1_DUTY,CONTACT_PERSON1_SEX,CONTACT_PERSON1_OFFICE_TEL,CONTACT_PERSON1_HOME_TEL,CONTACT_PERSON1_MOBILE,CONTACT_PERSON1_FAX,CONTACT_PERSON1_EMAIL,CONTACT_PERSON1_FAVORITE,CONTACT_PERSON2,CONTACT_PERSON2_DEPARTMENT,CONTACT_PERSON2_DUTY,CONTACT_PERSON2_SEX,CONTACT_PERSON2_OFFICE_TEL,CONTACT_PERSON2_HOME_TEL,CONTACT_PERSON2_MOBILE,CONTACT_PERSON2_FAX,CONTACT_PERSON2_EMAIL,CONTACT_PERSON2_FAVORITE,INVOICE_INFO,DEMAND,REMARK,CHECK_TAG,CONTACT_AMOUNT,ACHIEVEMENT_SUM,ATTACHMENT_NAME,TRADE_AMOUNT,RETURN_SUM,RETURN_AMOUNT,GATHER_PERIOD_SUM,GATHER_PERIOD_AVERAGE,FILE_CHANGE_AMOUNT,GATHER_PERIOD_LIMIT,GATHER_SUM_LIMIT,CONTACT_PERIOD_LIMIT,USED_CUSTOMER_NAME,REGISTER,CHECKER,CHANGER,REGISTER_ID,CHECKER_ID,CHANGER_ID,REGISTER_TIME,CHECK_TIME,CHANGE_TIME,LATELY_CHANGE_TIME,LATELY_TRADE_TIME,LATELY_CONTACT_TIME,DELETE_TIME,RECOVERY_TIME,SALES_NAME,SALES_ID,MODIFY_TAG,EXCEL_TAG,REMIND_CONTACT_TAG,REMIND_GATHER_TAG,REMIND_RETURN_TAG,OPINION) values('")).append(rs8.getString("CHAIN_ID")).append("','").append(rs8.getString("CHAIN_NAME")).append("','").append(rs8.getString("CUSTOMER_ID")).append("','").append(rs8.getString("CUSTOMER_NAME")).append("','").append(rs8.getString("CUSTOMER_NICK")).append("','").append(rs8.getString("CUSTOMER_ADDRESS")).append("','").append(rs8.getString("CUSTOMER_CLASS")).append("','").append(rs8.getString("TYPE")).append("','").append(rs8.getString("CUSTOMER_BANK")).append("','").append(rs8.getString("CUSTOMER_ACCOUNT")).append("','").append(rs8.getString("CUSTOMER_WEB")).append("','").append(rs8.getString("CUSTOMER_TEL1")).append("','").append(rs8.getString("CUSTOMER_TEL2")).append("','").append(rs8.getString("CUSTOMER_EMAIL")).append("','").append(rs8.getString("CUSTOMER_FAX")).append("','").append(rs8.getString("CUSTOMER_POSTCODE")).append("','").append(rs8.getString("CONTACT_PERSON1")).append("','").append(rs8.getString("CONTACT_PERSON1_DEPARTMENT")).append("','").append(rs8.getString("CONTACT_PERSON1_DUTY")).append("','").append(rs8.getString("CONTACT_PERSON1_SEX")).append("','").append(rs8.getString("CONTACT_PERSON1_OFFICE_TEL")).append("','").append(rs8.getString("CONTACT_PERSON1_HOME_TEL")).append("','").append(rs8.getString("CONTACT_PERSON1_MOBILE")).append("','").append(rs8.getString("CONTACT_PERSON1_FAX")).append("','").append(rs8.getString("CONTACT_PERSON1_EMAIL")).append("','").append(rs8.getString("CONTACT_PERSON1_FAVORITE")).append("','").append(rs8.getString("CONTACT_PERSON2")).append("','").append(rs8.getString("CONTACT_PERSON2_DEPARTMENT")).append("','").append(rs8.getString("CONTACT_PERSON2_DUTY")).append("','").append(rs8.getString("CONTACT_PERSON2_SEX")).append("','").append(rs8.getString("CONTACT_PERSON2_OFFICE_TEL")).append("','").append(rs8.getString("CONTACT_PERSON2_HOME_TEL")).append("','").append(rs8.getString("CONTACT_PERSON2_MOBILE")).append("','").append(rs8.getString("CONTACT_PERSON2_FAX")).append("','").append(rs8.getString("CONTACT_PERSON2_EMAIL")).append("','").append(rs8.getString("CONTACT_PERSON2_FAVORITE")).append("','").append(rs8.getString("INVOICE_INFO")).append("','").append(rs8.getString("DEMAND")).append("','").append(rs8.getString("REMARK")).append("','").append(rs8.getString("CHECK_TAG")).append("','").append(rs8.getString("CONTACT_AMOUNT")).append("','").append(rs8.getString("ACHIEVEMENT_SUM")).append("','").append(rs8.getString("ATTACHMENT_NAME")).append("','").append(rs8.getString("TRADE_AMOUNT")).append("','").append(rs8.getString("RETURN_SUM")).append("','").append(rs8.getString("RETURN_AMOUNT")).append("','").append(rs8.getString("GATHER_PERIOD_SUM")).append("','").append(rs8.getString("GATHER_PERIOD_AVERAGE")).append("','").append(rs8.getString("FILE_CHANGE_AMOUNT")).append("','").append(rs8.getString("GATHER_PERIOD_LIMIT")).append("','").append(rs8.getString("GATHER_SUM_LIMIT")).append("','").append(rs8.getString("CONTACT_PERIOD_LIMIT")).append("','").append(rs8.getString("USED_CUSTOMER_NAME")).append("','").append(rs8.getString("REGISTER")).append("','").append(rs8.getString("CHECKER")).append("','").append(rs8.getString("CHANGER")).append("','").append(rs8.getString("REGISTER_ID")).append("','").append(rs8.getString("CHECKER_ID")).append("','").append(rs8.getString("CHANGER_ID")).append("','").append(rs8.getString("REGISTER_TIME")).append("','").append(rs8.getString("CHECK_TIME")).append("','").append(rs8.getString("CHANGE_TIME")).append("','").append(rs8.getString("LATELY_CHANGE_TIME")).append("','").append(rs8.getString("LATELY_TRADE_TIME")).append("','").append(rs8.getString("LATELY_CONTACT_TIME")).append("','").append(rs8.getString("DELETE_TIME")).append("','").append(rs8.getString("RECOVERY_TIME")).append("','").append(rs8.getString("SALES_NAME")).append("','").append(rs8.getString("SALES_ID")).append("','").append(rs8.getString("MODIFY_TAG")).append("','").append(rs8.getString("EXCEL_TAG")).append("','").append(rs8.getString("REMIND_CONTACT_TAG")).append("','").append(rs8.getString("REMIND_GATHER_TAG")).append("','").append(rs8.getString("REMIND_RETURN_TAG")).append("','").append(rs8.getString("OPINION")).append("')").toString();
									crm_db.executeUpdate(sqll);
								}
								String sql = (new StringBuilder("update crm_file set chain_id='")).append(chain_id).append("',chain_name='").append(chain_name).append("',customer_name='").append(customer_name).append("',customer_address='").append(customer_address).append("',customer_class='").append(customer_class).append("',type='").append(type).append("',customer_bank='").append(customer_bank).append("',customer_account='").append(customer_account).append("',customer_web='").append(customer_web).append("',customer_tel1='").append(customer_tel1).append("',customer_tel2='").append(customer_tel2).append("',customer_fax='").append(customer_fax).append("',customer_postcode='").append(customer_postcode).append("',used_customer_name='").append(used_customer_name).append("',gather_sum_limit='").append(gather_sum_limit).append("',gather_period_limit='").append(gather_period_limit).append("',contact_period_limit='").append(contact_period_limit).append("',contact_person1='").append(contact_person1).append("',contact_person1_department='").append(contact_person1_department).append("',contact_person1_duty='").append(contact_person1_duty).append("',contact_person1_sex='").append(contact_person1_sex).append("',contact_person1_office_tel='").append(contact_person1_office_tel).append("',contact_person1_home_tel='").append(contact_person1_home_tel).append("',contact_person1_mobile='").append(contact_person1_mobile).append("',contact_person1_email='").append(contact_person1_email).append("',contact_person2='").append(contact_person2).append("',contact_person2_department='").append(contact_person2_department).append("',contact_person2_duty='").append(contact_person2_duty).append("',contact_person2_sex='").append(contact_person2_sex).append("',contact_person2_office_tel='").append(contact_person2_office_tel).append("',contact_person2_home_tel='").append(contact_person2_home_tel).append("',contact_person2_mobile='").append(contact_person2_mobile).append("',contact_person2_email='").append(contact_person2_email).append("',changer_ID='").append(changer_ID).append("',changer='").append(changer).append("',invoice_info='").append(invoice_info).append("',demand='").append(demand).append("',remark='").append(remark).append("',change_time='").append(change_time).append("',lately_change_time='").append(lately_change_time).append("',file_change_amount='").append(change_amount).append("',check_tag='0',excel_tag='1' where customer_ID='").append(customer_ID).append("'").toString();
								crm_db.executeUpdate(sql);
								sql = (new StringBuilder("delete from crm_workflow where object_id='")).append(customer_ID).append("'").toString();
								crm_db.executeUpdate(sql);
								List rsList = GetWorkflow.getList(crm_db, "crm_config_workflow", "01");
								if (rsList.size() == 0)
								{
									sql = (new StringBuilder("update crm_file set check_tag='1' where customer_ID='")).append(customer_ID).append("'").toString();
									crm_db.executeUpdate(sql);
									sql = (new StringBuilder("delete from ecommerce_workflow where object_id='")).append(customer_ID).append("'").toString();
									crm_db.executeUpdate(sql);
									List rsList1 = GetWorkflow.getList(crm_db, "ecommerce_config_workflow", "02");
									if (rsList1.size() == 0)
									{
										sql = (new StringBuilder("update crm_file set excel_tag='3' where customer_ID='")).append(customer_ID).append("'").toString();
										crm_db.executeUpdate(sql);
									} else
									{
										for (Iterator ite = rsList1.iterator(); ite.hasNext(); crm_db.executeUpdate(sql))
										{
											String elem[] = (String[])ite.next();
											sql = (new StringBuilder("insert into ecommerce_workflow(config_id,object_ID,describe1,describe2) values ('")).append(elem[0]).append("','").append(customer_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
										}

									}
								} else
								{
									for (Iterator ite = rsList.iterator(); ite.hasNext(); crm_db.executeUpdate(sql))
									{
										String elem[] = (String[])ite.next();
										sql = (new StringBuilder("insert into crm_workflow(config_id,object_ID,describe1,describe2) values ('")).append(elem[0]).append("','").append(customer_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
									}

								}
							}
							catch (Exception ex)
							{
								ex.printStackTrace();
							}
							response.sendRedirect((new StringBuilder("ecommerce/crm/change_choose_attachment.jsp?customer_ID=")).append(customer_ID).toString());
						} else
						{
							response.sendRedirect((new StringBuilder("ecommerce/crm/change_ok_a.jsp?customer_ID=")).append(customer_ID).toString());
						}
					} else
					{
						response.sendRedirect((new StringBuilder("ecommerce/crm/change_ok_b.jsp?customer_ID=")).append(customer_ID).toString());
					}
				} else
				{
					response.sendRedirect("ecommerce/crm/change_ok_c.jsp");
				}
				crm_db.commit();
				crm_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
